package org.chengn.level_hard.context828;

import java.util.HashMap;
import java.util.Map;

public class Context828TimeTLE {
    int ans = 0;
    public int uniqueLetterString(String s) {
        dp(s);
        return ans;
    }

    void dp(String s) {
        int len = s.length();
        for (int i = 0; i < s.length(); ++i) {
            Map<Character, Integer> map = new HashMap<>();
            int totalNum = 0;
            for (int j = i; j >= 0; --j) {
                char c = s.charAt(j);
                Integer num = map.getOrDefault(c, 0);
                if (num == 0) {
                    totalNum++;
                } else if (num == 1) {
                    totalNum--;
                } else {
                    // .. 已经超过两个了 不变
                }
                ans += totalNum;
                map.put(c, num + 1);
            }
        }
    }
}
